package book;

import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class BookStore {
    static Book[] books=new Book[6];
    static {
        books[0]=new Book(1,"go",25,50);
        books[1]=new Book(2,"Sql",30,50);
        books[2]=new Book(3,"C++",35,50);
        books[3]=new Book(4,"Web",40,50);
        books[4]=new Book(5,"PHP",45,50);
        books[5]=new Book(6,"jdk",50,50);
    }

    public static void main(String[] args) {
        showBook(books);
        Person p=new Person("黄冀宁");
        Book book=p.buyBook(books);
        showTotal(book,p);
    }

    public static void showBook(Book[] book) {
        System.out.println("图书编号\t图书名称\t图书价格\t库存数量");
        for (int i=0;i< book.length;i++){
            System.out.println(book[i].getId()+"\t\t"+book[i].getName()
                                +"\t\t"+book[i].getPrice()+"\t\t"+book[i].getStorage());
        }
    }

    public static void showTotal(Book book,Person p){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入购买数量");
        int num=sc.nextInt();
        Random random=new Random();
        int orderNum=random.nextInt();
        System.out.println("订单编号："+Math.abs(orderNum));
        System.out.println("购买时间："+ LocalDateTime.now());
        System.out.println("会员名称："+p.getName());
        System.out.println("购书名称："+book.getName()+"\t图书单价："+book.getPrice()
                            +"\t购买数量"+num);
        System.out.println("--------------总价："+num*book.getPrice()+"-----------");
    }
}
